#include "collisionpolygon.h"

#include <QPainter>

CollisionPolygon::CollisionPolygon(QDeclarativeItem *parent )
    : CollisionObject(parent)
{
    setFlag(QGraphicsItem::ItemHasNoContents, false);
}

void CollisionPolygon::setVertices(QVariantList vertices)
{
    m_Vertices = vertices;

    m_Polygon.clear();

    for (int i = 0; i < vertices.length(); i++)
        m_Polygon.append(vertices.at(i).toPoint());

    emit verticesChanged(m_Vertices);
}

void CollisionPolygon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                        QWidget *widget)
{
    Q_UNUSED(option)
    Q_UNUSED(widget)

    if (debug())
    {
        painter->save();
        painter->setPen(Qt::black);
        painter->setBrush(Qt::green);
        painter->drawPolygon(m_Polygon);
        painter->restore();
    }
}
